//
//  CMDBRefreshTableView.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/9.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBRefreshTableView: CMDBBaseTableView {

    override func setupTableView() {
        super.setupTableView()
        
        bounces = true
        
//        let header = MJRefreshNormalHeader(refreshingTarget: self, refreshingAction: #selector(CMDBRefreshTableView.loadNewStatuses))

        let header = MJRefreshGifHeader(refreshingTarget: self,refreshingAction:#selector(CMDBRefreshTableView.loadNewStatuses))
        
        header.setValue(true, forKeyPath: "stateLabel.hidden")
        
        header.setValue(true, forKeyPath: "lastUpdatedTimeLabel.hidden")
        
        header.setImages([UIImage(named: "1")!],forState:MJRefreshState.Idle)
        
        header.setImages([UIImage(named: "1")!],forState:MJRefreshState.Pulling)
        
        header.setImages(
            [UIImage(named: "8")!,
                UIImage(named: "7")!,
                UIImage(named: "6")!,
                UIImage(named: "5")!,
                UIImage(named: "4")!,
                UIImage(named: "3")!,
                UIImage(named: "2")!,
                UIImage(named: "1")!],forState:MJRefreshState.Refreshing)
        
        mj_header = header
        
        mj_header.beginRefreshing()
        
        let footer = MJRefreshAutoFooter(refreshingTarget: self, refreshingAction: #selector(CMDBRefreshTableView.loadMoreStatuses))
        
        mj_footer = footer
        
        mj_footer.hidden = true
    }
}

extension CMDBRefreshTableView {
    
    @objc private func loadNewStatuses() {
        mDelegate?.onHeaderRefresh!()
    }
    @objc private func loadMoreStatuses() {
        mDelegate?.onFooterRefresh!()
        
    }
}
